#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Solution
{
public:
    static int calculate(string s)
    {
        char op = '+';
        vector<int> st;
        int i=0, ret = 0;

        while(i<s.size())
        {
            if(s[i] == ' ')
                i++;
            if(s[i] >= '0' && s[i] <= '9')
            {
                int tmp = 0;
                while(i<s.size() && s[i] >= '0' && s[i] <= '9')
                {
                    tmp = tmp*10 + (s[i]-'0');
                    i++;
                }
                if(op == '+')
                    st.push_back(tmp);
                else if(op == '-')
                    st.push_back(-tmp);
                else if(op == '*')
                    st.back() = st.back()*tmp;
                else
                    st.back() = st.back()/tmp;
            }
            if(s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/')
            {
                op = s[i];
            }
            i++;
        }
        for(auto e : st)
        {
            ret += e;
        }
        return ret;
    }
};
